//隐式动画
import 'package:flutter/material.dart';

class ImplicitAnimPage extends StatefulWidget {
  const ImplicitAnimPage({super.key, required this.title});

  final String title;

  @override
  State<ImplicitAnimPage> createState() => _ImplicitAnimPageState();
}

class _ImplicitAnimPageState extends State<ImplicitAnimPage> {
  int _counter = 0;
  bool isOpen = false;

  void _incrementCounter() {
    setState(() {
      _counter++;
      isOpen = !isOpen;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: SingleChildScrollView(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          spacing: 10,
          children: <Widget>[
            const Text(
              '隐式动画 如 AnimatedContainer、  AnimatedOpacity、 AnimatedPositioned、 AnimatedPadding、AnimatedAlign、AnimatedDefaultTextStyle 等',
            ),
            AnimatedContainer(
              duration: Duration(seconds: 1),
              width: isOpen ? 100 : 150,
              height: isOpen ? 100 : 150,
              alignment: isOpen ? Alignment.center : Alignment.topCenter,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(isOpen ? 0 : 15),
                color: isOpen ? Colors.red : Colors.blue,
              ),
              child: Text("Container 动画", style: TextStyle(color: Colors.white)),
            ),
            AnimatedOpacity(
              duration: Duration(seconds: 1),
              opacity: isOpen ? 1.0 : 0.0,
              child: Container(
                alignment: Alignment.center,
                color: Colors.blue,
                height: 100,
                child: Text("Opacity 动画", style: TextStyle(color: Colors.white)),
              ),
            ),
            AnimatedPadding(
              duration: Duration(seconds: 1),
              padding: EdgeInsets.all(isOpen ? 0 : 50),
              child: Container(
                alignment: Alignment.center,
                color: Colors.blue,
                height: 100,
                child: Text("Padding 动画", style: TextStyle(color: Colors.white)),
              ),
            ),
            AnimatedCrossFade(
              firstChild: Container(
                color: Colors.red,
                width: 100,
                height: 100,
              ),
              secondChild: Container(
                color: Colors.green,
                width: 100,
                height: 100,
              ),
              crossFadeState: isOpen ? CrossFadeState.showFirst : CrossFadeState.showSecond,
              duration: Duration(seconds: 1),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
